package jdbc;

import java.sql.Connection;
import java.sql.Statement;

public class JDBCDemo3 {
    public static void main(String[] args) {
        // 更新数据库里面的数据
        try(
                // 切记：需要实现AutoCloseable接口的类，才能使用try(){}
                Connection conn = DBUtil.getConnection();
                ){
            // sql语句
            String sql = "UPDATE userinfo "+
                    "SET nickname = '李太白' "+
                    "WHERE username = '李白'";

            Statement statement = conn.createStatement();
            int count = statement.executeUpdate(sql);
            if(count > 0){
                System.out.println("更新成功");
            }else{
                System.out.println("更新失败");
            }
        }catch (Exception e){
            e.printStackTrace();
        }


    }
}
